home *** CD-ROM | disk | FTP | other *** search
- /*
- * Utilities.c
- *
- * WASTE PROJECT
- * General purpose utility
- *
- * Copyright (c) 1993-1994 Marco Piovanelli
- * All Rights Reserved
- *
- */
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif __TYPES__
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif __MEMORY__
-
- #include "WASTEIntf.h"
- pascal Boolean _WEBlockCmp(register Ptr block1, register Ptr block2, register long blockSize)
- {
- for ( ; blockSize > 0 ; blockSize-- )
- if ( *block1++ != *block2++ )
- return false;
-
- return true;
- }
-
- pascal void _WEBlockClr(register Ptr block, register long blockSize)
- {
- for ( ; blockSize > 0; blockSize-- )
- *block++ = 0;
- }
-
- pascal void _WEForgetHandle(Handle *h)
- {
- Handle theHandle = *h;
-
- if (theHandle != NULL)
- {
- *h = NULL;
- DisposeHandle(theHandle);
- }
- }
-
- pascal Boolean _WESetHandleLock(Handle h, Boolean lock)
- {
- Boolean oldLock = (HGetState(h) & (1 << 7)) != 0;
-
- if (lock != oldLock)
- if (lock)
- HLock(h);
- else
- HUnlock(h);
-
- return oldLock;
- }
-
- pascal void _WEReorder(long *a, long *b)
- {
- if (*a > *b)
- {
- register long temp = *a;
- *a = *b;
- *b = temp;
- }
- }
-
- pascal OSErr _WEAllocate(Size blockSize, short allocFlags, Handle *h)
- {
- //{ Allocate a new relocatable block. }
- //{ AllocFlags may specify whether the block should be cleared and whether }
- //{ temporary memory should be used. }
-
- Handle theHandle;
- OSErr retval;
-
- theHandle = nil;
-
- //{ if kAllocTemp is specified, try tapping temporary memory }
- if ((allocFlags & kAllocTemp) != 0)
- {
- theHandle = TempNewHandle(blockSize, &retval);
- }
- //{ if kAllocTemp isn't specified, or TempNewHandle failed, try with current heap }
- if (theHandle == nil)
- {
- theHandle = NewHandle(blockSize);
- retval = MemError();
- }
-
- //{ if kAllocClear is specified, zero the block }
- if ((allocFlags & kAllocClear) != 0)
- {
- if (theHandle != nil)
- {
- _WEBlockClr(*theHandle, blockSize);
- }
- }
-
- //{ return handle through VAR parameter }
- *h = theHandle;
-
- return retval;
- }
-